package cn.ghf.product.service.impl;

import cn.ghf.basic.service.impl.BaseServiceImpl;
import cn.ghf.basic.util.PageList;
import cn.ghf.product.domain.Product;
import cn.ghf.product.mapper.ProductMapper;
import cn.ghf.product.query.ProductQuery;
import cn.ghf.product.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProductServiceImpl extends BaseServiceImpl<Product> implements IProductService {

    @Autowired
    private ProductMapper productMapper;
    /**
     * 分页查询所有
     * @param query
     * @return
     */
    @Override
    public PageList<Product> getProducts(ProductQuery query) {
        return super.queryData(query);
    }
    /**
     * 上架
     * @param ids
     */
    @Override
    public void onSale(List<Long> ids) {
        //product表根据ids更新state=1上架
        //更新上架时间
        Map<String,Object> map = new HashMap<>();
        map.put("ids",ids );
        map.put("onsaletime", new Date());
        productMapper.onsale(map);
    }

    /**
     * 下架
     * @param ids
     */
    @Override
    public void offSale(List<Long> ids) {
        //pet表根据ids更新state=0下架
        //更新下架时间
        Map<String,Object> map = new HashMap<>();
        map.put("ids",ids );
        map.put("offsaletime", new Date());
        productMapper.offSale(map);
    }
}
